public class GameDriver {
  boolean secret1;
  boolean secret2;
  boolean secret3;
  boolean secret4;
  boolean secret5;
  boolean secret6;
  boolean secret7;
  boolean secret8;
  boolean secret9;
  StartMenu sm;
  Map m;
  Combat c;
  Shop s;
  Player p;
  Inventory i;
  int currentStage = 0; // 0:Start Menu  1:Map Thingy  2:Combat  3:Shop  4:Inventory

  public GameDriver() {
    sm = new StartMenu();
  }

  public void keyboardAct() {
    if (currentStage == 0) {
      sm.keyboardAct();

      if (sm.ChangeStage) {
        p = sm.p1;
        currentStage = 1;
        m = new Map(p);
      }
    }
    if (currentStage == 1) {
      if (keyCode == UP) {
        secret1 = true;
      }

      if (keyCode == UP && secret1) {
        secret2 = true;
      }
      else {
        reset();
      }
      if (keyCode == DOWN && secret2) {
        secret3 = true;
      }
      else {
        reset();
      }
      if (keyCode == DOWN && secret3) {
        secret4 = true;
      }
      else {
        reset();
      }
      if (keyCode == LEFT && secret4) {
        secret5 = true;
      }
      else {
        reset();
      }
      if (keyCode == RIGHT && secret5) {
        secret6 = true;
      }
      else {
        reset();
      }
      if (keyCode == LEFT && secret6) {
        secret7 = true;
      }
      else {
        reset();
      }
      if (keyCode == RIGHT && secret7) {
        secret8 = true;
      }
      else {
        reset();
      }
      if (key == 'b' || key == 'B' && secret8) {
        secret9 = true;
      }
      else {
        reset();
      }
      if (key == 'a' || key == 'A' && secret9) {
        p.abilities.add("Instakill");
      }
      else {
        reset();
      }
    }
  }

  public void mouseAct(int x, int y) {
    if (currentStage == 0) {
      sm.mouseAct(x, y);
      if (sm.ChangeStage) {
        p = sm.p1;
        currentStage = 1;
        m = new Map(p);
      }
    }
    if (currentStage == 1) {
      m.mouseAct(x, y);
      if (m.combatchosen) {
        currentStage = 2;
        Random r = new Random();
        c = new Combat(p, r.nextInt(4)+1);
      }
      if (m.shopchosen) {
        currentStage = 3;
        s = new Shop(p);
      }
      if (m.inventorychosen) {
        currentStage = 4;
        i = new Inventory(p);
      }
    }
    if (currentStage == 2) {
      c.mouseAct(x, y);
      if (c.backtomap == true) {
        if (p.myXP >= p.myLvl*100) {
          p.myLvl++;
        }
        if (p.myLvl == 2) {
          p.abilities.add("Berserker");
        }
        if (p.myLvl == 4) {
          p.abilities.add("Poison");
        }
        if (p.myLvl == 5) {
          p.abilities.add("Icebeam");
        }
        if (p.myLvl == 7) {
          p.abilities.add("Regen");
        }
        if (p.myLvl == 8) {
          p.abilities.add("Sprint");
        }
        if (p.myLvl == 9) {
          p.abilities.add("Burn");
        }
        if (p.myLvl == 10) {
          p.abilities.add("Thunder");
        }
        
        currentStage = 1;
        m = new Map(p);
        p.myHP = p.baseHP;
        p.myFoc = p.baseFoc;
      }
    }
    if (currentStage == 3) {
      s.mouseAct(x, y);
      if (s.refresh == true) {
        s = new Shop(p);
      }
      if (s.backtomap == true) {
        currentStage = 1;
        m = new Map(p);
      }
    }
    if (currentStage == 4) {
      i.mouseAct(x, y);
      if (i.backtomap == true) {
        currentStage = 1;
        m = new Map(p);
      }
    }
  }
  private void reset() {
    secret1 = false;
    secret2 = false;
    secret3 = false;
    secret4 = false;
    secret5 = false;
    secret6 = false;
    secret7 = false;
    secret8 = false;
    secret9 = false;
  }
}

